<template>
  <div>
    <el-dialog
      title="审核"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      width="1000px"
      @closed="resetForm('form')"
      :lock-scroll="false"
    >
      <div>
        <el-form ref="form" :rules="rules" :model="form" label-width="80px">
          <el-form-item label="审批状态">
            <el-radio-group v-model="form.approverStatus">
              <el-radio label="2">同意</el-radio>
              <el-radio label="3">驳回</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="审批意见">
            <UEditor
              ref="ueditor"
              :ueHeight="ueHeight"
              :defaultMsg="form.approverOpinion"
            />
          </el-form-item>
        </el-form>
        <div class="investigate" v-show="checkedData.courseType < 10">
          <el-row :gutter="20">
            <el-col :span="8" v-if="tisp[0].isShow"
              ><el-checkbox v-model="checked1" disabled>
                {{ tisp[0].name }}</el-checkbox
              ></el-col
            >
            <el-col :span="5" v-if="tisp[1].isShow"
              ><el-checkbox v-model="checked1" disabled>
                {{ tisp[1].name }}</el-checkbox
              ></el-col
            >
            <el-col :span="8" v-if="tisp[2].isShow"
              ><el-checkbox v-model="checked1" disabled>
                {{ tisp[2].name }}</el-checkbox
              ></el-col
            >
          </el-row>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="custom" v-preventReClick @click="submitForm('form')"
          >提 交</el-button
        >
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { flowApiComplete } from '@/api/admin/audit/flowApi.js'
import Bus from '@/utils/bus.js'
export default {
  data() {
    return {
      checked1: true,
      dialogVisible: false,
      addOrEdit: 1,
      ueHeight: 200,
      checkedData: {},
      form: {
        id: '', //流程实例
        approverOpinion: '', //审批意见
        approverStatus: '2', //审批状态，2-同意，3-不同意
      },
      rules: {
        approverStatus: [
          { required: true, message: '请输入审批状态', trigger: 'blur' },
        ],
        approverOpinion: [
          { required: true, message: '请输入审批意见', trigger: 'blur' },
        ],
      },
      tisp: [
        { id: 1, isShow: true, name: '已通过保密审查（资源为秘密级以下）' },
        { id: 2, isShow: true, name: '已通过政治审查' },
        { id: 3, isShow: true, name: '已完成线下保密、政治审查流程' },
      ],
    }
  },
  mounted() {
    Bus.$on('showDialogReview', (v) => {
      this.ueHeight = v.courseType > 10 ? 200 : 400
      this.checkedData = v
      this.form.id = v.id
      this.showAuditTips()
      this.dialogVisible = true
    })
  },
  beforeDestroy() {
    Bus.$off('showDialogReview')
  },
  methods: {
    submitForm(form) {
      this.form.approverOpinion = this.$refs.ueditor.message
      this.$refs[form].validate((valid) => {
        if (valid) {
          this.add()
        }
      })
    },
    //新增
    add() {
      flowApiComplete(this.form).then((res) => {
        this.dialogVisible = false
        Bus.$emit('flowRunTaskList')
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
    showAuditTips() {
      this.homeConfig = JSON.parse(this.getSession('homeConfig')) || []
      let obj1 = this.homeConfig.find((v) => v.code == 'autip01')
      let obj2 = this.homeConfig.find((v) => v.code == 'autip02')
      let obj3 = this.homeConfig.find((v) => v.code == 'autip03')
      if (obj1) {
        this.tisp[0].isShow = obj1.isShow == 0
        this.tisp[0].name = obj1.name
      }
      if (obj2) {
        this.tisp[1].isShow = obj2.isShow == 0
        this.tisp[1].name = obj2.name
      }
      if (obj3) {
        this.tisp[2].isShow = obj3.isShow == 0
        this.tisp[2].name = obj3.name
      }
    },
    //重置表单
    resetForm(form) {
      this.$refs[form].resetFields()
      this.form.id = ''
      this.form.approverOpinion = ''
      this.form.approverStatus = '2'
    },
  },
}
</script>
<style scoped>
.investigate {
  box-sizing: border-box;
  padding-left: 80px;
}
</style>